package com.macro.mall.controller;

import com.macro.mall.common.api.CommonPage;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.model.TiTraining;
import com.macro.mall.service.TiTrainingService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * TiTraining的路由接口服务
 *
 * @author
 */
@Slf4j
@RestController
@RequestMapping("TiTrainingController")
@Api(tags = "专题信息表", description = "专题信息表")
public class TiTrainingController {

    /**
     * TiTrainingService服务
     */
    @Autowired
    private TiTrainingService tiTrainingService;

    /**
     * 查询所有数据的方法
     *
     * @param
     * @return
     */
    @GetMapping(value = "/list", produces = {"application/json;charset=UTF-8"})
    public CommonResult find(@RequestParam(value = "name",required = false) String name,
                             @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                             @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize) {
        return CommonResult.success(CommonPage.restPage(tiTrainingService.find(name, pageNum, pageSize)));
    }

    /**
     * 通过id查询数据的方法
     *
     * @param id
     * @return
     */
    @GetMapping(value = "/getById", produces = {"application/json;charset=UTF-8"})
    public CommonResult findOne(@RequestParam(name = "id") Integer id) {
        return CommonResult.success(tiTrainingService.findOne(id));
    }

    /**
     * 插入CiCollegeInfo属性不为空的数据方法
     *
     * @param
     * @return
     */
    @PostMapping(value = "/save", produces = {"application/json;charset=UTF-8"})
    public CommonResult save(@Valid @RequestBody TiTraining value) {
        tiTrainingService.saveNotNull(value);
        return CommonResult.success(null);
    }

    /**
     * 更新CiCollegeInfo属性不为空的数据方法
     *
     * @param
     * @return
     */
    @PostMapping(value = "/update", produces = {"application/json;charset=UTF-8"})
    public CommonResult update(@Valid @RequestBody TiTraining value) {
        CommonResult data = tiTrainingService.updateNotNullById(value);
        return CommonResult.success(null);
    }

    /**
     * 通过id删除数据方法
     *
     * @param id
     * @return
     */
    @GetMapping(value = "/deleteId", produces = {"application/json;charset=UTF-8"})
    public CommonResult delete(@RequestParam(name = "id") Integer id) {
        CommonResult data = tiTrainingService.deleteById(id);
        return CommonResult.success(null);
    }
}
